package com.dgut.admodule.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dgut.admodule.dao.IBiddingDao;
import com.dgut.admodule.entity.Bidding;

@Service
@Transactional
public class BiddingService implements IBiddingService
{
	@Autowired
	private IBiddingDao biddingDao;
	
	public void saveOrUpdate(Bidding bid) {
		biddingDao.save(bid);
	}

	
	public void delete(Bidding bid) {
		biddingDao.delete(bid);
	}

	public void delete(List<Long> ids) {
		List<Bidding> bids =  (List<Bidding>) biddingDao.findAll(ids);
		if(bids!=null) {
			biddingDao.delete(bids);
		}
	}

	@Transactional(readOnly = true)
	public Bidding findOne(Long id) {
		return biddingDao.findOne(id);
	}

	@Transactional(readOnly = true)
	public Bidding findNew() 
	{
		Long newId = 0L;
		for (Bidding b : biddingDao.findAll()) {
			newId = b.getBidId();
		}
		if(newId==0L) {return new Bidding();}
		else{return biddingDao.findOne(newId);}
	}
	
	@Transactional(readOnly = true)
	public List<Bidding> findAll() {
		return (List<Bidding>) biddingDao.findAll();
	}

	@Transactional(readOnly = true)
	public Page<Bidding> findAll(Specification<Bidding> spec, Pageable pageable) {
		return biddingDao.findAll(spec, pageable);
	}
	
}
